WHAT IS THIS?

The ComplexUtils class implements support for complex numbers with Double precision.
The ComplexWrappers Module consists mainly of wrappers for the ComplexUtils class for 
convenience, as well as a few functions for conversions. The class can be used without the module.



CREATING A NEW COMPLEX VARIABLE

The Constructor accepts optional arguments of type double or string to assign a value to the
complex number when it is first initialized:

E.g.

dim c1 as new Complex // Real and Imaginary parts are initialized to 0
dim c2 as new Complex(1,-3) // Real part = 1 and Imaginary part = -3
dim c3 as new Complex("3+5j") // Real part = 3 and Imaginary part = 5

The string for the latter case must be formatted like one of theses examples:
"3+5j", "-2.56+3.72j", "4-1.1j", "4", "2j", "-2.41", "-1.23j", " -3j+2", "1j-5.41"

The imaginary part identifier "j" must be accompanied by a number, i.e. "1+j" is not a
valid string. The identifier can be "j", "J", "i", or "I".


If the ComplexWrappers module is installed, complex numbers can also be created
with one of the following functions:

Cmpl(r, i) // returns a new Complex number with real part r and imaginary part i
Re(d) // returns a new "real" Complex with real part d, i.e. it converts a real number to it's complex equivalent
Im(d) // creates a complex number with imaginary part d, the real part is 0
Pol2Rect(abs, arg) // creates a complex number with absolute value abs and argument arg

These functions can be used in expressions as follows:

dim c as Complex
dim a as Double = 1.234
dim b as Double = -5.678

c = a + b * Im(1) // c = a + bj



RECTANGULAR AND POLAR COORDINATES

The value of a complex number can be assigned and obtained in both rectangular or polar coordinates
in one of these ways:

// Assigning value in rectangular coordinates, e.g. 3-4j
c = new Complex(3,-4)

c = new Complex
c = Cmpl(3,-4) // requires ComplexWrappers module

c = new Complex
c.Real = 3
c.Imag = -4

// Obtaining value in rectangular coordinates
r = c.Real
i = c.Imag

r = Real(c) // requires ComplexWrappers module
i = Imag(c) // requires ComplexWrappers module

// Assigning value in polar coordinates
c = new Complex
c.Pol2Rect(1, 1.414)

c = Pol2Rect(1, 1.414) // requires ComplexWrappers module

// Obtaining value in polar coordinates
ab = c.Abs
ar = c.Arg

ab = Abs(c) // requires ComplexWrappers module
ar = Arg(c) // requires ComplexWrappers module



// STANDARD OPERATORS

The standard operators +, -, *, /, and ^ are overloaded with the appropriate functions to allow the use
of these operators with complex numbers. Each of these operators accepts either complex numbers
or built-in numerical data types (Integer, Double, etc.) on one or both sides.

E.g. using the + operator, two complex numbers can be added, or a double can be added to a complex number:

dim c1 as new Complex(2,5)
dim c2 as new Complex(4,-6)
dim c3, c4 as Complex
dim d as double = 1.234

c3 = c1 + c2
c4 = d + c3

The same syntax also applies to the other standard operators.



// STRING CONVERSIONS

Complex numbers can be converted to strings in the following ways:

s = Str(c)
s = CStr(c)
s = c.Format(FormatSpec) // See RB Language Reference for information on FormatSpec
s = Format(c, FormatSpec)  // requires ComplexWrappers module



// ADVANCED FUNCTIONS

The following advanced functions have been implemented:

Conj        // returns the complex conjugate of a complex number
Inv         // returns the inverse of a complex number
Norm        // returns the norm (square "length") of a complex number
Sqrt        // returns the square root of a complex number
Exp         // returns the exponential of a complex number
Log         // returns the natural logarithm of a complex number
Sin         // returns the sine of a complex number
Cos         // returns the cosine of a complex number
Tan         // returns the tangent of a complex number
Cot         // returns the cotangent of a complex number
Sec         // returns the secant of a complex number
Cosec       // returns the cosecant of a complex number
Asin        // returns the arc sine of a complex number
Acos        // returns the arc cosine of a complex number
Atan        // returns the arc tangent of a complex number
Sinh        // returns the hyperbolic sine of a complex number
Cosh        // returns the hyperbolic cosine of a complex number
Tanh        // returns the hyperbolic tangent of a complex number
Asinh       // returns the inverse hyperbolic sine of a complex number
Acosh       // returns the inverse hyperbolic cosine of a complex number
Atanh       // returns the inverse hyperbolic tangent of a complex number

All these functions are part of the ComplexUtils class, and they are also implemented
as convenient wrappers in the ComplexWrappers module.


